package org.example.syn;

import org.openjdk.jol.info.ClassLayout;

import javax.management.monitor.Monitor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author Yyming
 * @version 10.0
 * Created by Yyming on 2020/8/10
 */
public class SynTest {
    public static void main(String[] args) throws InterruptedException {
        TimeUnit.SECONDS.sleep(5);
        Object o = new Object();
        System.out.println(ClassLayout.parseInstance(o).toPrintable());
        synchronized (o) {
            int a = 1;
            System.out.println(ClassLayout.parseInstance(o).toPrintable());
        }
        System.out.println(ClassLayout.parseInstance(o).toPrintable());
        new Thread(()->{
            synchronized (o) {
                int b = 1;
                System.out.println(ClassLayout.parseInstance(o).toPrintable());
            }
        }).start();
        //睡眠1s防止上面的线程还没有释放锁
        TimeUnit.SECONDS.sleep(1);
        System.out.println(ClassLayout.parseInstance(o).toPrintable());
    }
}

